
function Write-Parameters {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true, HelpMessage = "Parameter file path.")][string]$File,
        [Parameter(Mandatory = $true, HelpMessage = "Parameters object to write to file.")][Parameters]$Parameters
    )

    # Check if there are any parameters.
    if (!$Parameters) {
        Write-Verbose "No parameters to write to file."
    }

    # Clone the Parameters object so we can make changes to it.
    $Parameters = $Parameters.Clone()

    # Write parameters to file.
    if ($File) {

        if ($Parameters.LSInsight.Server.Credential) {
            $Parameters.LSInsight.Server.UserName = $Parameters.LSInsight.Server.Credential.UserName
            $Parameters.LSInsight.Server.Credential = $null
        }

        if ($Parameters.LSCentral.Server.Credential) {
            $Parameters.LSCentral.Server.UserName = $Parameters.LSCentral.Server.Credential.UserName
            $Parameters.LSCentral.Server.Credential = $null
        }

        Write-Verbose "Writing parameters to file."
        $Parameters | ConvertTo-Json | Set-Content -Path $File
    }

    <#
    .SYNOPSIS
        Writes parameters to file.
    .DESCRIPTION
        The Write-Parameters function writes deployment parameters, necessary for the LS Insight deployment, to a file.

        This function opens up the possibility of storing and reusing deployment parameters between different deployment processes.
    .EXAMPLE
        PS C:\> Write-Parameters -File "C:\Users\User1\Documents\Params.json" -Parameters $Params
        
        Stores $Params of type 'Parameter' in a file with the path "specified".
    .INPUTS
        None. You cannot pipe objects to Write-Parameters.
    .OUTPUTS
        Parameters. Write-Parameters returns an LS Insight deployment parameter object.
    .PARAMETER File
        Specifies the path to the parameters json file.
        Required?                    true
        Position?                    
        Default value
        Accept pipeline input?       false
        Accept wildcard characters?  false
    .PARAMETER Parameters
        A 'Parameters' type object that should be written to the file.
        Required?                    true
        Position?                    
        Default value
        Accept pipeline input?       false
        Accept wildcard characters?  false
    #>
}

